<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
    class Controller_Dialog extends Controller {

        public function action_addBlock() {
            $view = View::factory('addBlock');

            // fetch the blocktypes, and pass them to the view
            $view->types = Array();

            $query = DB::query(Database::SELECT, 'SELECT ID,Title FROM types');
            $types = $query->execute();

            for($i=0;$i<$types->count();$i++){
                $currentType = $types->current();

                $view->types[$i] = array(
                    'ID' => $currentType['ID'],
                    'Title' => $currentType['Title'],
                );

                $types->next();
            }
            
            $this->request->response = $view;
        }

        public function action_error($error) {
            $view = View::factory('errorDialog');

            $view->error = $error;
            
            $this->request->response = $view;
        }


        public function action_editBlock($id){
            $query = DB::query(Database::SELECT, 'SELECT * FROM blocks WHERE id = :blockid');
            $query->param(':blockid',$id);
            $blocks = $query->execute();

            $currentBlock = $blocks->current();

            $type = DB::query(Database::SELECT, 'SELECT title FROM types WHERE id = :typeid');
            $type->param(':typeid',$currentBlock['type']);
            $type = $type->execute();
            $type = $type->current();

            $view = View::factory('actions/edit/blocktypes/'.$type['title']);

            $view->ID = $id;
            $view->SETTING = $currentBlock['setting'];
            $view->TITLE = $currentBlock['title'];

            $this->request->response = $view;
        }

    }
?>